public class FamilyAccount {
    public static void main(String[] args) {

        String details="收支\t\t\t账户金额\t\t\t收支金额\t\t\t说明\n";//收支的变量
        boolean isFlag=true;//打标记
        int balance = 0;//总金额

        while (isFlag){
            System.out.println("-----------------家庭收支记账软件-----------------\n");
            System.out.println("                   1 收支明细");
            System.out.println("                   2 登记收入");
            System.out.println("                   3 登记支出");
            System.out.println("                   4 退    出\n");
            System.out.print("                  请选择(1-4)：");
            char selection = Utility.readMenuSelection();
            switch (selection){
                //1 收支明细功能
                case '1':
                    System.out.println("-----------------当前收支明细记录-----------------");
                    System.out.println(details);
                    System.out.println("-----------------------------------------------");
                    break;
                //2 登记收入功能
                case '2':
                    //登记收入
                    System.out.print("本次收入金额：");
                    int money = Utility.readNumber();
                    System.out.print("本次收入说明：");
                    String str = Utility.readString();
                    //处理总金额
                    balance+=money;
                    //处理details
                    details+=("收入\t\t\t"+balance+"\t\t\t"+money+"\t\t\t"+str+"\n");
                    System.out.println("-------------------登记完成-------------------\n");
                    break;

                //2 登记支出功能
                case '3':
                    //登记支出
                    System.out.print("本次支出金额：");
                    int money2 = Utility.readNumber();
                    System.out.print("本次支出说明：");
                    String str2 = Utility.readString();

                    //处理总金额
                    if (balance>=money2) {
                        balance-=money2;
                        //处理details
                        details+=("支出\t\t\t"+balance+"\t\t\t"+money2+"\t\t\t"+str2+"\n");
                        System.out.println("-------------------登记完成-------------------\n");
                    } else {
                        System.out.println("余额不足，支付失败");
                        System.out.println("-------------------登记失败-------------------\n");

                    }

                    break;

                //退出功能
                case '4':
                    System.out.println("确认是否退出(Y/N)：");
                    char c = Utility.readConfirmSelection();
                    if (c == 'Y') {
                        isFlag=false;
                    }
                    //break;
            }
            //isFlag=false;
        }
    }
}
